package com.binguo.wxapi.controller;


import com.binguo.common.exception.ErrorCode;
import com.binguo.model.api.vo.BinguoOrderVO;
import com.binguo.model.model.SideBoard;
import com.binguo.model.model.SideBoardCells;
import com.binguo.model.wxapi.vo.SideBoardVO;
import com.binguo.service.OrderService;
import com.binguo.wxapi.form.PhoneMealsForm;
import com.binguo.wxapi.form.aiyouwei.BindCustomerBoardForm;
import com.binguo.wxapi.form.aiyouwei.SaveOrderForm;
import com.binguo.wxapi.result.Result;
import com.binguo.wxapi.result.ResultGenerator;
import com.binguo.wxapi.service.AiyouweiTestService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;


@RestController
public class AiyouweiTestController {

    private static final Logger logger = LoggerFactory.getLogger(AiyouweiTestController.class);

    @Autowired
    private AiyouweiTestService aiyouweiTestService;
    @Autowired
    private OrderService orderService;


    /**
     * 查询分店是否对存餐和保温设置了价格
     * @param sideBoardVO
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getMealsPriceAndWarmPrice")
    public Result getIsWramAndIsMeals(SideBoardVO sideBoardVO){
        SideBoardVO sideBoardVO_ = aiyouweiTestService.getIsWramAndIsMeals(sideBoardVO);
        return sideBoardVO_ == null ? ResultGenerator.genFailResult("未查询到商户！"):ResultGenerator.genSuccessResult(sideBoardVO_);
    }

    /**
     * 更新或添加存餐和加热价格
     * @param sideBoardVO
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/updateShopConfigExtend")
    public Result updataShopConfigExtend(@RequestBody SideBoardVO sideBoardVO){
        Integer i =
                sideBoardVO.getId() == 0 ? aiyouweiTestService.addShopConfigExtend(sideBoardVO):aiyouweiTestService.updateShopConfigExtend(sideBoardVO);
        return i > 0 ?  ResultGenerator.genSuccessResult("操作成功！"):ResultGenerator.genFailResult("操作失败！");
    }

    /**
     * 订单详细页面查询存餐和加热价格
     * @param orderId
     * @return
     */
    @GetMapping(value = "/api/wxapp/detail/surcharge/{orderId}")
    public Result getSurcharge(@PathVariable String orderId){
        BinguoOrderVO binguoOrderVO = orderService.getSurcharge(orderId);
        if (binguoOrderVO == null) {
            return ResultGenerator.genFailResult("订单不存在！");
        }
        if(null == binguoOrderVO.getIsMeals()){
            return ResultGenerator.genFailResult("该订单未选择存餐！");
        }if(binguoOrderVO.getIsMeals() >0){
            return ResultGenerator.genSuccessResult(aiyouweiTestService.getOrderSideBoardVO(binguoOrderVO,orderId));
        }else{
            return ResultGenerator.genFailResult("该订单未选择存餐！");
        }
    }

    /**
     * 获取订单详细页面二维码
     * @return Base64图片编码
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getQrCodeBase64")
    public Result getQrCodeBase64(SaveOrderForm saveOrderForm){
        return ResultGenerator.genSuccessResult(aiyouweiTestService.getQrCode(saveOrderForm));
    }

    /**
     * 存餐码存餐
     * @param saveOrderForm
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/saveOrderByMealCode")
    public Result saveOrderByMealCode(@RequestBody SaveOrderForm saveOrderForm){
        if(saveOrderForm.getMealCode() == null || saveOrderForm.getMealCode().equals("")
                || saveOrderForm.getBranchId() == null || saveOrderForm.getBranchId().equals("")
                || saveOrderForm.getShopId() == null || saveOrderForm.getShopId().equals("")
        ){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.saveOrderByMealCode(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 取餐码取餐
     * @param saveOrderForm
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
    @PostMapping(value = "/api/wxapp/aiyouwei/getOrderByMealCode")
    public Result getOrderByMealCode(@RequestBody SaveOrderForm saveOrderForm) throws Exception {
        if(saveOrderForm.getMealCode() == null || saveOrderForm.getMealCode().equals("")
                || saveOrderForm.getBranchId() == null || saveOrderForm.getBranchId().equals("")
                || saveOrderForm.getShopId() == null || saveOrderForm.getShopId().equals("")
        ){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.getOrderByMealCode(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     *订单页面查询订单状态
     * @param orderId
     * @return  0未存，1已存未取，2已取
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getOrderStatus/{orderId}")
    public Result getOrderStatus(@PathVariable String orderId){
        ErrorCode errorCode = aiyouweiTestService.getShopOrderStatus(orderId);
        return getResult(errorCode);
    }

    /**
     * 根据取餐柜id 查询柜格状态
     * @param id  取餐柜id
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getAllSideBoardCells/{id}")
    public Result getAllSideBoardCells(@PathVariable Integer id){
        List<SideBoardCells> list = aiyouweiTestService.selectAllSideBoardCell(id);
        if(list.size()>0){
            return ResultGenerator.genSuccessResult(list);
        }else{
            return ResultGenerator.genFailResult("当前分店不存在该取餐柜！");
        }
    }

    /**
     * 查询分店对应的取餐柜
     * @param shopId
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getSideBoardByShopIdAndBranchId/{shopId}/{branchId}")
    public Result getSideBoardsByShopId(@PathVariable Integer shopId,@PathVariable Integer branchId){
        List<SideBoard> sideBoards = aiyouweiTestService.getBranchSideBoard(branchId,shopId);
        if(sideBoards.size()>0){
            return ResultGenerator.genSuccessResult(sideBoards);
        }else{
            return ResultGenerator.genFailResult("未查询到取餐柜!");
        }
    }

    /**
     * 查询商户是否有取餐柜
     * @param shopId
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getSideBoardByShopId/{shopId}")
    public Result getSideBoardsByShopId_(@PathVariable Integer shopId){
        List<SideBoard> sideBoards = aiyouweiTestService.getShopSideBoard(shopId);
        if(sideBoards.size()>0){
            return ResultGenerator.genSuccessResult(sideBoards);
        }else{
            return ResultGenerator.genFailResult("未查询到取餐柜!");
        }
    }

    /**
     * 批量开柜
     * @param id
     * @param cells
     * @return
     * @throws IOException
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/openCellByCellNo")
    public Result openCellsByCellNo(Integer id,String  cells,@RequestParam(value = "type", required = false) Integer type){
        if (type == null) {
            type = 1;
        }
        if(type == 1 ){
            ErrorCode errorCode = aiyouweiTestService.openCellsByCellNo(cells,id);
            return getResult(errorCode);
        }else if(type == 2){
            ErrorCode errorCode = aiyouweiTestService.openCellsByCellNoAndUpdateRecode(cells,id);
            return getResult(errorCode);
        }else{
            return getResult(ErrorCode.TYPE_ERROR);
        }
    }

    /**
     * 效验取餐码是否正确
     * @param saveOrderForm
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/isTrueCode")
    public Result isTrueCode(@RequestBody SaveOrderForm saveOrderForm){
       ErrorCode errorCode= aiyouweiTestService.isTrueCode(saveOrderForm.getMealCode());
       return getResult(errorCode);
    }

    /**
     * 微信小程序二维码取餐
     * @param
     * @return
     */
    @PostMapping("/api/wxapp/aiyouwei/openCellByCustomerCode")
    public Result openCellByCustomerCode(@RequestBody SaveOrderForm saveOrderForm){
        if(saveOrderForm.getCustomerCode() == null  || saveOrderForm.getCustomerCode().equals("")){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.getOrderByCustomerCode(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 刷卡取餐
     * @param
     * @return
     */
    @PostMapping("/api/wxapp/aiyouwei/openCellByCard")
    public Result openCellByCard(@RequestBody SaveOrderForm saveOrderForm){
        ErrorCode errorCode = aiyouweiTestService.getOrderByPayCard(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     *人脸取餐
     * @param
     * @return
     */
    @PostMapping("/api/wxapp/aiyouwei/openCellByFace")
    public Result openCellByFace(@RequestBody SaveOrderForm saveOrderForm){
        ErrorCode errorCode = aiyouweiTestService.getOrderByFace(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 手机号存餐
     * @param form
     * @return
     */
    @PostMapping("/api/wxapp/aiyouwei/saveOrderByPhone")
    public Result saveOrderByPhone(@RequestBody PhoneMealsForm form){
        ErrorCode errorCode = aiyouweiTestService.saveOrderByPhone(form);
        return getResult(errorCode);
    }


    /**
     * 检查订单支付状态
     * @param saveOrderForm
     * @return
     * @throws IOException
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/beforeOpenCell")
    public Result beforeOpenCell(SaveOrderForm saveOrderForm) throws Exception {
        if(null == saveOrderForm.getMealCode() || saveOrderForm.getMealCode().equals("")){
            return ResultGenerator.genFailResult("参数错误");
        }
        if(saveOrderForm.getOrgin() == null){
            saveOrderForm.setOrgin(0);
        }
        ErrorCode errorCode = aiyouweiTestService.beforeOpenCell(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 获取支付二维码
     * @param saveOrderForm
     * @return
     * @throws IOException
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getPayCode")
    public Result getPayCode(SaveOrderForm saveOrderForm){
        if(null == saveOrderForm.getMealCode() || saveOrderForm.getMealCode().equals("")){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode= aiyouweiTestService.getPayCode(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 查询支付状态
     * @param saveOrderForm
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getPayResult")
    public Result getPayResult(SaveOrderForm saveOrderForm){
        if(null == saveOrderForm.getMealCode() || saveOrderForm.getMealCode().equals("")){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.checkOrderPayStatus(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 获取百度人脸sdk序列号
     * @param deviceId
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getBaiduSDKSerial")
    public Result getBaiduSDKSerial(String deviceId){
        if(deviceId.equals("") || null == deviceId){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.getBaiduSdkSerier(deviceId);
        return getResult(errorCode);
    }

    /**
     * 通用返回结果
     * @param errorCode
     * @return
     */
    public Result getResult(ErrorCode errorCode){
        if(errorCode.getCode() == 200){
            if(null != errorCode.getData()){
                return ResultGenerator.genSuccessResult(errorCode.getData());
            }else{
                return ResultGenerator.genSuccessResult();
            }
        }else{
            Result result = new Result();
            if(errorCode.getCode() == 9000 ){
                result.setCode(401);
                result.setData(errorCode.getData());
            }else if(errorCode.getCode() == 9018 ){
                result.setCode(402);
                result.setData(errorCode.getData());
            }else{
                result.setCode(400);
            }

            result.setMessage(errorCode.getMessage());
            return result;
        }
    }

    /**
     * 获取取餐柜初始化状态
     * @param deviceId
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getSideBoardInitStatus")
    public Result getSideBoardInitStatus(String deviceId){
        if(StringUtils.isEmpty(deviceId)){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.getSideBoardInitStatus(deviceId);
        return getResult(errorCode);
    }

    /**
     * 更新极光推送唯一标识
     * @param sideBoardVO
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/updateJpushRegisterId")
    public Result updateJpushRegisterId(@RequestBody SideBoardVO sideBoardVO){
        if(StringUtils.isEmpty(sideBoardVO.getCashierDeskId())
                || StringUtils.isEmpty(sideBoardVO.getJpushRegisterId())
                || sideBoardVO.getCellNum() == 0
                || StringUtils.isEmpty(sideBoardVO.getName()))
        {
            return ResultGenerator.genFailResult("参数错误！");
        }
        if(StringUtils.isEmpty(sideBoardVO.getType())){
            sideBoardVO.setType(0);
        }
        ErrorCode errorCode = aiyouweiTestService.updateJPushRegisterId(sideBoardVO);
        return getResult(errorCode);
    }

    /**
     * 增加副柜
     * @param sideBoardVO
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/addSunSideBoard")
    public Result addSunSideBoard(@RequestBody SideBoardVO sideBoardVO){
        logger.info("进入增加副柜功能,入参:"+sideBoardVO);
        if(sideBoardVO.getCashierDeskId() == null
                || sideBoardVO.getBranchId() == null
                || sideBoardVO.getShopId() == null
                || sideBoardVO.getCellNum() == 0){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.addSunSideBoard(sideBoardVO);
        return getResult(errorCode);
    }

    /**
     * 获取副柜列表
     * @param sideBoardVO
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getSunSideBoard")
    public Result getSunSideBoard(SideBoardVO sideBoardVO){
        if(sideBoardVO.getCashierDeskId() == null
        ){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode  = aiyouweiTestService.getSunSideBoard(sideBoardVO);
        return getResult(errorCode);
    }

    /**
     * 删除副柜
     * @param sideBoardVO
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/deleteSunBoard")
    public Result deleteSunBoard(SideBoardVO sideBoardVO){
        if(sideBoardVO.getId() == null
        ){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode  = aiyouweiTestService.deleteSunSideBoard(sideBoardVO);
        return getResult(errorCode);
    }

    /**
     * 生成二维码
     * @param sideBoardVO
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/generateMiniProgramCode")
    public Result generateMiniProgramCode(@RequestBody SideBoardVO sideBoardVO)throws Exception{
        if (sideBoardVO.getCashierDeskId() == null){
            return ResultGenerator.genFailResult("参数错误！");
        }
        logger.info("生成小程序码");
        ErrorCode errorCode = aiyouweiTestService.generateMiniProgramCode(sideBoardVO.getCashierDeskId().toString());
        return getResult(errorCode);
    }

    /**
     * 根据cashierDeskId获取取餐柜
     * @param cashierDeskId
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getSideBoardByCashierDeskId")
    public Result getSideBoardByCashierDeskId(@Param("cashierDeskId") Integer cashierDeskId){
        if(StringUtils.isEmpty(cashierDeskId)){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.getSideBoardByCashierDeskId(cashierDeskId);
        return getResult(errorCode);
    }

    /**
     * 获取用户在当前分店的所有取餐码
     * @param shopId
     * @param branchId
     * @param customerId
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getCustomerMealCode/{shopId}/{branchId}/{customerId}")
    public Result getCustomerMealCode(@PathVariable Integer shopId,@PathVariable Integer branchId,@PathVariable Integer customerId){
        ErrorCode errorCode = aiyouweiTestService.getCustomerMealCode(branchId,shopId,customerId);
        return getResult(errorCode);
    }

    /**
     * 手机号存餐第三种
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/saveOrderByPhoneForJY")
    public Result saveOrderByPhoneForJY(@RequestBody PhoneMealsForm phoneMealsForm) throws Exception {
        if(phoneMealsForm.getCashierDeskId() == null
                || phoneMealsForm.getCashierDeskId().equals("")
                || phoneMealsForm.getCells() == null || phoneMealsForm.getCells().equals("")
                || phoneMealsForm.getIsWarm() == null || phoneMealsForm.getIsWarm().equals("")
                || phoneMealsForm.getShopId() == null || phoneMealsForm.getShopId().equals("")
                || phoneMealsForm.getBranchId() == null || phoneMealsForm.getBranchId().equals("")){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.saveOrderByPhoneForJY(phoneMealsForm);
        return getResult(errorCode);
    }

    /**
     * 获取用户在当前分店的所有取餐码
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/updateSideBoard/{id}/{sideBoardName}")
    public Result updateSideBoard(@PathVariable Integer id,@PathVariable String sideBoardName){
        ErrorCode errorCode = aiyouweiTestService.updateSideBoard(id,sideBoardName);
        return getResult(errorCode);
    }

    /**
     * 获取订单详细页面二维码
     * @return Base64图片编码
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getOrderDetails")
    public Result getOrderDetails(SaveOrderForm saveOrderForm){
        return ResultGenerator.genSuccessResult(aiyouweiTestService.getQrCode(saveOrderForm));
    }

    /**
     * 根据扫码得到的请求地址下单
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/saveOrderByZSDQrCode")
    public Result saveOrderByZSDQrCode(@RequestBody SaveOrderForm saveOrderForm) throws Exception {
        if(StringUtils.isEmpty(saveOrderForm.getCashierDeskId())
        || StringUtils.isEmpty(saveOrderForm.getShopId())
        || StringUtils.isEmpty(saveOrderForm.getBranchId())
        || StringUtils.isEmpty(saveOrderForm.isWarm())
        || StringUtils.isEmpty(saveOrderForm.getCellNo())){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.saveOrderByZSDQrCode(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 浙师大扫码取餐
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/getOrderByZSDQrCode")
    public Result getOrderByZSDQrCode(@RequestBody SaveOrderForm saveOrderForm)throws Exception{
        if(StringUtils.isEmpty(saveOrderForm.getCashierDeskId())
                || StringUtils.isEmpty(saveOrderForm.getShopId())
                || StringUtils.isEmpty(saveOrderForm.getBranchId())
                || StringUtils.isEmpty(saveOrderForm.getOrderUrl())){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.getOrderByZSDQrCode(saveOrderForm);
        return getResult(errorCode);
    }


    /**
     * 多个取餐码取餐
     * @param saveOrderForm
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
    @PostMapping(value = "/api/wxapp/aiyouwei/getOrderByMealCodes")
    public Result getOrderByMealCodes(@RequestBody SaveOrderForm saveOrderForm) throws Exception {
        if(saveOrderForm.getMealCode() == null || saveOrderForm.getMealCode().equals("")
                || saveOrderForm.getBranchId() == null || saveOrderForm.getBranchId().equals("")
                || saveOrderForm.getShopId() == null || saveOrderForm.getShopId().equals("")
        ){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.getOrderByMealCode(saveOrderForm);
        return getResult(errorCode);
    }


    /**
     * 查找出当前分店下所有的双开柜有锁面
     * @return
     */
    @GetMapping(value = "/api/wxapp/aiyouwei/getAllCustomerBoard/{branchId}/{cashierDeskId}")
    public Result getAllCustomerBoardByBranchId(@PathVariable Integer branchId,@PathVariable Integer cashierDeskId) {
        ErrorCode errorCode = aiyouweiTestService.getAllCustomerBoard(branchId,cashierDeskId);
        return getResult(errorCode);
    }

    /**
     * 绑定客户面柜子
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/bindCustomerBoard")
    public Result bindCustomerBoard(@RequestBody BindCustomerBoardForm form) {
        if(StringUtils.isEmpty(form.getCustomerBoardId())
                || StringUtils.isEmpty(form.getCashierDeskId())
        ){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.bindCustomerBoard(form);
        return getResult(errorCode);
    }

    /**
     * 恒大双开柜取餐逻辑
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/hendaGetOrder")
    public Result hendaGetOrder(@RequestBody SaveOrderForm saveOrderForm){
        if(StringUtils.isEmpty(saveOrderForm.getCashierDeskId())
        || StringUtils.isEmpty(saveOrderForm.getShopId())
        || StringUtils.isEmpty(saveOrderForm.getBranchId())
        || (StringUtils.isEmpty(saveOrderForm.getMealCode()) && StringUtils.isEmpty(saveOrderForm.getOrderId()))){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.hendaGetOrder(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 恒大双开柜取餐逻辑
     * @return
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/hendaSaveOrder")
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
    public Result hendaSaveOrder(@RequestBody SaveOrderForm saveOrderForm) throws Exception {
        if(StringUtils.isEmpty(saveOrderForm.getCashierDeskId())
                || StringUtils.isEmpty(saveOrderForm.getShopId())
                || StringUtils.isEmpty(saveOrderForm.getBranchId())
                || StringUtils.isEmpty(saveOrderForm.getCellNo())
                || StringUtils.isEmpty(saveOrderForm.getOrgin())){
            return ResultGenerator.genFailResult("参数错误");
        }
        ErrorCode errorCode = aiyouweiTestService.hendaSaveOrder(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 青橄榄下单接口调用此接口在云澎系统中生成订单号与取餐码
     * @return
     */
    @PostMapping(value="/api/wxapp/aiyouwei/getMealCodeByOrderSn")
    public Result getMealCodeByOrderSn(@RequestBody SaveOrderForm saveOrderForm) throws ParseException {
        if(StringUtils.isEmpty(saveOrderForm.getOrderUrl())
                || StringUtils.isEmpty(saveOrderForm.getAppId())
                || StringUtils.isEmpty(saveOrderForm.getSign())){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.getMealCodeByOrderUrl(saveOrderForm);
        return getResult(errorCode);
    }
    /**
     * 存餐选择柜子开门
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/saveOrderByChooseCellNo")
    public Result saveOrderByChooseCellNo(@RequestBody SaveOrderForm saveOrderForm){
        if(StringUtils.isEmpty(saveOrderForm.getCashierDeskId())
                || StringUtils.isEmpty(saveOrderForm.getShopId())
                || StringUtils.isEmpty(saveOrderForm.getBranchId())
                || StringUtils.isEmpty(saveOrderForm.isWarm())
                || StringUtils.isEmpty(saveOrderForm.getCellNo())){
            return ResultGenerator.genFailResult("参数错误！");
        }
        ErrorCode errorCode = aiyouweiTestService.saveOrderByChooseCellNo(saveOrderForm);
        return getResult(errorCode);
    }

    /**
     * 根据扫码得到的请求地址下单
     */
    @PostMapping(value = "/api/wxapp/aiyouwei/saveOrderByZSDQrCodeOrMealCode")
    public Result saveOrderByZSDQrCodeOrMealCode(@RequestBody SaveOrderForm saveOrderForm){
        if(StringUtils.isEmpty(saveOrderForm.getCashierDeskId())
                || StringUtils.isEmpty(saveOrderForm.getShopId())
                || StringUtils.isEmpty(saveOrderForm.getBranchId())
                || StringUtils.isEmpty(saveOrderForm.isWarm())
                || StringUtils.isEmpty(saveOrderForm.getCellNo())){
            return ResultGenerator.genFailResult("参数错误！");
        }
//        ErrorCode errorCode = aiyouweiTestService.saveOrderByZSDQrCode(saveOrderForm);
        ErrorCode errorCode = aiyouweiTestService.saveOrderByZSDQrCodeOrMealCode(saveOrderForm);
        return getResult(errorCode);
    }
}
